local skel = fk.CreateSkill {
  name = "rmt_hongdang__rulv",
  tags = { Skill.Permanent },
}

Fk:loadTranslationTable{
  ["rmt_hongdang__rulv"] = "如律",
  [":rmt_hongdang__rulv"] = "持恒技，每回合限X次，一名角色的判定结果生效前，你可以将判定结果改为♠（X为你受到雷电伤害次数，至多为3）。",

  ["$rmt_hongdang__rulv"] = "胎光延生，爽灵益禄，幽精绝死，急急如律令。",
}

skel:addEffect(fk.AskForRetrial, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and data.card.suit ~= Card.Spade and
      player:usedSkillTimes(skel.name, Player.HistoryTurn) < player:getMark(skel.name)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = skel.name,
      prompt = "#rfenghou__rulv-invoke::"..target.id..":"..data.reason,
    }) then
      event:setCostData(self, {tos = {target}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local new_card = Fk:cloneCard(data.card.name, Card.Spade, data.card.number)
    new_card.skillName = skel.name
    new_card.id = data.card.id
    data.card = new_card
    room:sendLog{
      type = "#ChangedJudge",
      from = player.id,
      to = { data.who.id },
      arg2 = new_card:toLogString(),
      arg = skel.name,
    }
  end,
})

skel:addEffect(fk.Damaged, {
  can_refresh = function (self, event, target, player, data)
    return target == player and data.damageType == fk.ThunderDamage and player:getMark(skel.name) < 3
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addPlayerMark(player, skel.name, 1)
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  if not is_start then
    local room = player.room
    local n = math.min(3, #room.logic:getActualDamageEvents(3, function (e)
      local damage = e.data
      return damage.to == player and damage.damageType == fk.ThunderDamage
    end, Player.HistoryGame))
    room:setPlayerMark(player, skel.name, n)
  end
end)

return skel
